<h2 align="center">
    <?php
    include_once "../model/model.php";
    include_once "../model/pile.php";

    if (isset($_POST["name"]) && $_POST["name"] != "" && $_POST["year"] != "" && $_POST["month"] != "" && $_POST["day"] != "") {
        $date = $_POST["year"] . "-" . $_POST["month"] . "-" . $_POST["day"];
        $now = date("Y-n-j");
		$pattern = "/0([1-9])/";
		$replacement = "$1";
		$_POST["month"] = preg_replace($pattern, $replacement, $_POST["month"]);
        if (is_numeric($_POST["month"]) && is_numeric($_POST["day"]) && is_numeric($_POST["year"])) {
            if (checkdate($_POST["month"], $_POST["day"], $_POST["year"])) {
                if (strtotime($date) >= strtotime($now)) {
                    //echo "123";
                    $night = new NIGHT();
                    switch ($night->check($_POST["name"], $date, $_POST["detail"])) {
                        case NIGHT::refuse:
                            echo "您没有使用权";
                            break;

                        case NIGHT::submitted:
                            echo "您已提交申请!";
                            break;

                        case NIGHT::waitting:
                            echo "申请已提交，等待管理员审核……";
                            break;

                        default:
                            echo "system error!";
                            break;
                    }
                } else
                    echo "请输入有效时间！";
            }
        } else
            echo "请输入有效时间！";
    }
    else {
        echo "请填写完整信息！";
    }
    ?>
    <a href="../user/form2.php">返回</a>
</h2>
